<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <!-- 主表单区域 -->
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24" >
            <a-form-model-item label="招标项目id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectId">
              <a-input v-model="model.projectId" placeholder="请输入招标项目id" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24" >
            <a-form-model-item label="招标项目编号 - 参照电子招标投标系统技术规范第1部分：交易平台技术规范的附录b.3.4招标项目编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenderProjectCode">
              <a-input v-model="model.tenderProjectCode" placeholder="请输入招标项目编号 - 参照电子招标投标系统技术规范第1部分：交易平台技术规范的附录b.3.4招标项目编号" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24" >
            <a-form-model-item label="标段（包）编号 - 参照电子招标投标系统技术规范第1部分：交易平台技术规范的附录b.3.5标段（包）编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bidSectionCode">
              <a-input v-model="model.bidSectionCode" placeholder="请输入标段（包）编号 - 参照电子招标投标系统技术规范第1部分：交易平台技术规范的附录b.3.5标段（包）编号" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24" >
            <a-form-model-item label="统一交易标识码 - 参考附录n统一交易标识码编码方案" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="unifiedDealCode">
              <a-input v-model="model.unifiedDealCode" placeholder="请输入统一交易标识码 - 参考附录n统一交易标识码编码方案" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24" >
            <a-form-model-item label="变更公告标识码 - 交易系统中使用或生成的唯一码,数据交换时新增或修改的依据" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="noticeId">
              <a-input v-model="model.noticeId" placeholder="请输入变更公告标识码 - 交易系统中使用或生成的唯一码,数据交换时新增或修改的依据" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24" >
            <a-form-model-item label="公告标题 - 自由文本" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="noticeName">
              <a-input v-model="model.noticeName" placeholder="请输入公告标题 - 自由文本" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24" >
            <a-form-model-item label="公告内容 - 自由文本" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="noticeContent">
              <j-editor v-model="model.noticeContent" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24" >
            <a-form-model-item label="公告发布时间 - yyyymmddhhmmss" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="noticeSendTime">
              <j-date placeholder="请选择公告发布时间 - yyyymmddhhmmss" v-model="model.noticeSendTime" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24" >
            <a-form-model-item label="公告结束时间 - yyyymmddhhmmss" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="noticeEndTime">
              <j-date placeholder="请选择公告结束时间 - yyyymmddhhmmss" v-model="model.noticeEndTime" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24" >
            <a-form-model-item label="公告发布媒体 - 多个以半角分号分割" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="noticeMedia">
              <a-input v-model="model.noticeMedia" placeholder="请输入公告发布媒体 - 多个以半角分号分割" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24" >
            <a-form-model-item label="公告性质 - 参考b.9.3公告性质" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="noticeNature">
              <a-input v-model="model.noticeNature" placeholder="请输入公告性质 - 参考b.9.3公告性质" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24" >
            <a-form-model-item label="公告类型 - 参考b.9.4公告类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bulletinType">
              <a-input v-model="model.bulletinType" placeholder="请输入公告类型 - 参考b.9.4公告类型" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24" >
            <a-form-model-item label="交易系统标识码 - 采用gb 32100-2015 《法人和其他组织统一社会信用代码编码规则》" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="platformCode">
              <a-input v-model="model.platformCode" placeholder="请输入交易系统标识码 - 采用gb 32100-2015 《法人和其他组织统一社会信用代码编码规则》" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24" >
            <a-form-model-item label="数据时间戳 - 采用组合码，编码长度为14位数时间戳，由省级服务平台生成" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dataTimestamp">
              <a-input v-model="model.dataTimestamp" placeholder="请输入数据时间戳 - 采用组合码，编码长度为14位数时间戳，由省级服务平台生成" ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
      <!-- 子表单区域 -->
    <a-tabs v-model="activeKey" @change="handleChangeTabs">
      <a-tab-pane tab="更正公告与标段关联" :key="refKeys[0]" :forceRender="true">
        <j-vxe-table
          keep-source
          :ref="refKeys[0]"
          :loading="exGcChangebulletinSectionTable.loading"
          :columns="exGcChangebulletinSectionTable.columns"
          :dataSource="exGcChangebulletinSectionTable.dataSource"
          :maxHeight="300"
          :disabled="formDisabled"
          :rowNumber="true"
          :rowSelection="true"
          :toolbar="true"
          />
      </a-tab-pane>
    </a-tabs>
  </a-spin>
</template>

<script>

  import { getAction } from '@/api/manage'
  import { JVxeTableModelMixin } from '@/mixins/JVxeTableModelMixin.js'
  import { JVXETypes } from '@/components/jeecg/JVxeTable'
  import { getRefPromise,VALIDATE_FAILED} from '@/components/jeecg/JVxeTable/utils/vxeUtils.js'
  import { validateDuplicateValue } from '@/utils/util'
  import JFormContainer from '@/components/jeecg/JFormContainer'

  export default {
    name: 'ExChangeResultAnnoForm',
    mixins: [JVxeTableModelMixin],
    components: {
      JFormContainer,
    },
    data() {
      return {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        model:{
         },
        // 新增时子表默认添加几行空数据
        addDefaultRowNum: 1,
        validatorRules: {
           projectId: [
              { required: true, message: '请输入招标项目id!'},
           ],
           tenderProjectCode: [
              { required: true, message: '请输入招标项目编号 - 参照电子招标投标系统技术规范第1部分：交易平台技术规范的附录b.3.4招标项目编号!'},
           ],
           bidSectionCode: [
              { required: true, message: '请输入标段（包）编号 - 参照电子招标投标系统技术规范第1部分：交易平台技术规范的附录b.3.5标段（包）编号!'},
           ],
           unifiedDealCode: [
              { required: true, message: '请输入统一交易标识码 - 参考附录n统一交易标识码编码方案!'},
           ],
           noticeId: [
              { required: true, message: '请输入变更公告标识码 - 交易系统中使用或生成的唯一码,数据交换时新增或修改的依据!'},
           ],
           noticeName: [
              { required: true, message: '请输入公告标题 - 自由文本!'},
           ],
           noticeContent: [
              { required: true, message: '请输入公告内容 - 自由文本!'},
           ],
           noticeSendTime: [
              { required: true, message: '请输入公告发布时间 - yyyymmddhhmmss!'},
           ],
           noticeEndTime: [
              { required: true, message: '请输入公告结束时间 - yyyymmddhhmmss!'},
           ],
           noticeMedia: [
              { required: true, message: '请输入公告发布媒体 - 多个以半角分号分割!'},
           ],
           noticeNature: [
              { required: true, message: '请输入公告性质 - 参考b.9.3公告性质!'},
           ],
           bulletinType: [
              { required: true, message: '请输入公告类型 - 参考b.9.4公告类型!'},
           ],
           platformCode: [
              { required: true, message: '请输入交易系统标识码 - 采用gb 32100-2015 《法人和其他组织统一社会信用代码编码规则》!'},
           ],
           dataTimestamp: [
              { required: true, message: '请输入数据时间戳 - 采用组合码，编码长度为14位数时间戳，由省级服务平台生成!'},
           ],
        },
        refKeys: ['exGcChangebulletinSection', ],
        tableKeys:['exGcChangebulletinSection', ],
        activeKey: 'exGcChangebulletinSection',
        // 更正公告与标段关联
        exGcChangebulletinSectionTable: {
          loading: false,
          dataSource: [],
          columns: [
            {
              title: '标段/包与变更公告关联标识码 - 交易系统中使用或生成的唯一码,数据交换时新增或修改的依据',
              key: 'sectionwinbulletid',
               type: JVXETypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue:'',
              validateRules: [{ required: true, message: '${title}不能为空' }],
            },
            {
              title: '统一交易标识码',
              key: 'unifiedDealCode',
               type: JVXETypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue:'',
              validateRules: [{ required: true, message: '${title}不能为空' }],
            },
            {
              title: '标段/包标识码',
              key: 'sectionid',
               type: JVXETypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue:'',
              validateRules: [{ required: true, message: '${title}不能为空' }],
            },
            {
              title: '标段（包）名称',
              key: 'sectionname',
               type: JVXETypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue:'',
              validateRules: [{ required: true, message: '${title}不能为空' }],
            },
            {
              title: '变更公告标识码',
              key: 'noticeId',
               type: JVXETypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue:'',
              validateRules: [{ required: true, message: '${title}不能为空' }],
            },
            {
              title: '交易系统标识码 - 采用gb 32100-2015 《法人和其他组织统一社会信用代码编码规则》',
              key: 'platformCode',
               type: JVXETypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue:'',
              validateRules: [{ required: true, message: '${title}不能为空' }],
            },
            {
              title: '数据时间戳 - 采用组合码，编码长度为14位数时间戳，由省级服务平台生成',
              key: 'dataTimestamp',
               type: JVXETypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue:'',
              validateRules: [{ required: true, message: '${title}不能为空' }],
            },
          ]
        },
        url: {
          add: "/exTenderAnnQuaInqueryAnn/exChangeResultAnno/add",
          edit: "/exTenderAnnQuaInqueryAnn/exChangeResultAnno/edit",
          queryById: "/exTenderAnnQuaInqueryAnn/exChangeResultAnno/queryById",
          exGcChangebulletinSection: {
            list: '/exTenderAnnQuaInqueryAnn/exChangeResultAnno/queryExGcChangebulletinSectionByMainId'
          },
        }
      }
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
    },
    methods: {
      addBefore(){
        this.exGcChangebulletinSectionTable.dataSource=[]
      },
      getAllTable() {
        let values = this.tableKeys.map(key => getRefPromise(this, key))
        return Promise.all(values)
      },
      /** 调用完edit()方法之后会自动调用此方法 */
      editAfter() {
        this.$nextTick(() => {
        })
        // 加载子表数据
        if (this.model.id) {
          let params = { id: this.model.id }
          this.requestSubTableData(this.url.exGcChangebulletinSection.list, params, this.exGcChangebulletinSectionTable)
        }
      },
      //校验所有一对一子表表单
        validateSubForm(allValues){
            return new Promise((resolve,reject)=>{
              Promise.all([
              ]).then(() => {
                resolve(allValues)
              }).catch(e => {
                if (e.error === VALIDATE_FAILED) {
                  // 如果有未通过表单验证的子表，就自动跳转到它所在的tab
                  this.activeKey = e.index == null ? this.activeKey : this.refKeys[e.index]
                } else {
                  console.error(e)
                }
              })
            })
        },
      /** 整理成formData */
      classifyIntoFormData(allValues) {
        let main = Object.assign(this.model, allValues.formValue)
        return {
          ...main, // 展开
          exGcChangebulletinSectionList: allValues.tablesValue[0].tableData,
        }
      },
      validateError(msg){
        this.$message.error(msg)
      },

    }
  }
</script>

<style scoped>
</style>